home *** CD-ROM | disk | FTP | other *** search
-
- Since I've downloaded so much useful software from this bulletin board, I
- felt inclined to contribute some. These are some DOS functions that I
- use quite a bit. Most of them have been tested pretty much, but they're
- free so no warranties. Hope someone out there gets some use from
- these.
-
- Tom Serface
-
-
- ACCESS.C --
- int access() - See if a file exists and can be opened.
- Returns 0 (NO) 1 (YES)
-
- ANNUITY.C --
- double annuity(r,i,n,y)
- This calculates the future value realized given a
- regular deposit to an annuity, nominal interest rate,
- number of deposits per year, and the total number of
- of deposits that will be made (assumes 1 deposit per period)
-
- double r = regular deposit
- double i = annual interest rate
- int n = number of deposits per year
- int y = number of total deposits
-
- BETWEEN.C --
- int between(sm,sd,sy,m,d,y)
- Returns the number of days between two dates
- int sm = Start Month
- int sd = Start Day
- int sy = Start Year
- int m = End Month
- int d = End Day
- int y = End Year
-
- BREAK.A --
- int GetBreak() - Get Current Setting of the DOS Break Command
- Returns: 0=Off
- 1=On
- void SetBreak(breakval) - Set the Dos Break Command
- Where:
- int BreakVal = 0 for OFF 1 for ON
-
- CENTER.C --
- void center(s2,s1,ncols) - Center a String into Another String
- Where:
- char *s1 = the string to center
- char *s2 = the destination string
- int ncols = the number of columns
-
- s2 must be at least ncols wide or memory problems occur
-
- CHDIR.A --
- int ChDir(directory) - Change Directory
- Returns: 0=changed directory successfully
- 3=not a good path in str
- 5=could not change directory
- Where:
- char *directory = String with path name
-
- COPY.C --
- int copy(from,to) - copy file named FROM to file named TO.
- Returns: 0=error
- 1=worked
- Where:
- char *from = file to copy
- char *to = new name of a file to create
-
- If a file named TO exists, it is deleted prior to copy.
-
-
- CRC.C --
- There are two kinds of checksums that can be used. The first is
- simply the sum of the bytes without paying attention to carry. This will
- work most of the time, and is 1 byte per packet faster, but the second
- type CRC is a lot more reliable. The CRC is two bytes and is calculated
- as a polynomial. The algorithm is described in Andrew S. Tanenbaum's
- book "Computer Networks" and will detect single and double bit errors
- all errors with an odd number of bits, all burst errors 16 bits or
- less, 99.997% of 17 bit burst errors, and 99.998% or 18 bit and longer
- bursts.
-
- short crc(string,len) - Calculate 2 byte CRC
- Returns: Calculated CRC
- Where:
- char *string = string to use for CRC calculation
- int len = length of the string
-
- short chksum(string,len) - Calculate 1 byte checksum without paying
- attention to carry.
- Returns: Calculated CheckSum
- Where:
- char *string = string to use for CRC calculation
- int len = length of the string
-
- short crcfile(fName) - Calculate 2 byte CRC for a file.
- Returns: Calculated CRC
- Where:
- char *fName = name of file to check
- This is useful for comparing 2 files to make sure that they
- are exactly the same.
-
- CURDSK.A --
- int CurDsk() - Get Current Disk Number
- Returns: 0=A (Drive Number)
- 1=B
- 2=C
- .
- .
-
- DAYOFWK.C --
- int dayofwk(month,day,year) - Returns the day of the week.
- Returns: 0=Sunday
- 1=Monday
- 2=Tuesday
- .
- .
- .
- Where:
- int month
- int day
- int year
-
- DAYOFYR.C --
- int dayofyr(month,day,year) - Returns the day of the year.
- Returns: 1=Jan 1st
- 2=Jan 2nd
- .
- .
- .
- Where:
- int month
- int day
- int year
-
- DISK.A --
- long DiskSize(disk,&total);
- Returns: Free space remaining on drive
- -1 if the drive is invalid
- Where:
- int disk = disk number 0=default, 1=A, 2=B, 3=C ...
- long *total = buffer to store total disk size
-
- EFFECTIVE.C --
- double effective(p,f,n,y)
- Returns:
- This calculates the effective interest rate for an investment
- given the initial amount, the expected future amount, the
- number of compounding periods per year, and the total number
- of periods the investment will exist.
- Where:
- double p = principal (initial investment)
- double f = future value of the investment
- int n = number of payments per year
- int y = number of total payments
-
- EQUIP.A --
- unsigned equip() - Get equipment status
- Returns: 2 byte equipment status
-
- unsighned Hdisks() - Get number of hard disks
- Returns: Number of Fixed Disks.
-
-
- EQUIPMENT.C --
- int equipment(type) - See what is hooked onto the PC.
- Returns: number of a particular equipment type.
- 0 if there is and error or none of a particular type
- Where:
- int type = type of equipment to query
- Types are:
- 1 - printers
- 2 - game ports
- 3 - rs232 ports
- 4 - diskette drives
- 5 - initial video mode
- 0 40x25 BW with color card
- 2 80x25 BW with color card
- 7 monochrome
- 6 - number of fixed disks
-
- FDATE.C
- char *fdate(buffer);
- Formatted date and time (Day Month Day, Year Time am/pm)
- e.g., Monday May 13, 1985 8:25pm
- This routine should be called with a buffer that has at least
- 40 characters.
- Returns: The address of the buffer you passed thru so that
- you can do stuff like printf("%s",fdate(buffer));
-
-
- FINDFIRST.A --
- DOS 2.0 functions to find files given filespec the argument to
- FindFirst() is a pointer to a filespec containing d:\path\filespec
- and an integer permission attribute for the files to find.
- FindNext() simply continues and fills in the DTA area with the file
- matching the next pattern.
- In the calling program you would first call SetDta(&dataArea);
- and then call FindFirst(filespec,attr) finally subsequent calls to
- FindNext(attr) can be made.
- The filename and attributes can be read from dataArea.
-
- FileFind.h must be included in any subroutines using these routines.
- Attributes for FindFirst, FindNext, GetMod, and ChMod
- You can set or check with '&' e.g., (attr & F_DIRECTORY)
- if(attr & (F_READ_ONLY & F_HIDDEN)
- F_NORMAL 0x00
- F_READ_ONLY 0x01
- F_HIDDEN 0x02
- F_SYSTEM 0x04
- F_LABEL 0x08
- F_DIRECTORY 0x10
- F_ARCHIVE 0x20
- F_ALL 0xFF
-
- struct DataArea {
- char dta_reserved[21];
- char dta_attribute;
- short int dta_time;
- short int dta_date;
- long int dta_file_size;
- char dta_name[13];
- } ;
-
- void SetDta(&DTA) - Set up DTA for Wild Card Conversions or whatever
- This version assumes that the Struct is in the programs DS.
- Where:
- dataArea = struct *DataArea DTA
-
- void GetDta(&segment,&offset) - Get the current DTA segment and offset
- Where:
- unsigned segment = segment of the DTA
- unsigned offset = offset from segment beginning
-
- void RestDta(segment,offset) - Restore a saved DTA segment and offset
- Where:
- unsigned segment = saved DTA segment
- unsigned offset = saved offset from segment beginning
-
- int FindFirst(filespec,attr) - Find the First File From a Wild Card Pattern
- Returns: 0=not found
- 1=found
- Where:
- char *filespec = pattern of file name to find
- int attr = attribute for the file
- F_NORMAL 0x00
- F_READ_ONLY 0x01
- F_HIDDEN 0x02
- F_SYSTEM 0x04
- F_LABEL 0x08
- F_DIRECTORY 0x10
- F_ARCHIVE 0x20
- F_ALL 0xFF
-
- int FindNext(attr) - Find the Next File From a Wild Card Pattern
- Returns: 0=not found
- 1=found
- Where:
- int attr = attribute for the file
- F_NORMAL 0x00
- F_READ_ONLY 0x01
- F_HIDDEN 0x02
- F_SYSTEM 0x04
- F_LABEL 0x08
- F_DIRECTORY 0x10
- F_ARCHIVE 0x20
- F_ALL 0xFF
-
- FV.C --
- double fv(p,i,n,y)
- This calculates the future value that can be expected
- from an investment given the initial value, annual interest,
- number of compounding periods (e.g., months per year, and the total
- number of periods the investment will exist.
- Returns: Calculated future value
- Where:
- double p = present value
- double i = annual interest rate
- int n = number of periods per year
- int y = number of total periods
-
- GETDATE.A --
- int GetDate(&month,&day,&year) - Get Date Information
- Returns: day of the week
- Where:
- int month
- int day
- int year
-
- int SetDate(month,day,year) - Set Date Information
- Returns: 0=worked
- -1=error
- Where:
- int month
- int day
- int year
-
- GETDIR.A --
- int GetDir(drive,directory) - Get Current Directory
- Returns: 0Fh if invalid drive
- 0 if worked
- Where:
- int drive = disk number (0=default, 1=A, 2=B, 3=C ...)
- char *directory = buffer to store the directory path
- the buffer should be at least 85 chars
-
- GETPATH.C --
- int _exec(prog,args) - exec using PATH
- Execs a program after finding it in PATH
- Returns: -1=prog not found/error
- -2=not a .EXE or .COM file
- otherwise returns the return code from prog
- Where:
- char *prog=program to execute
- char *args=arguments for prog
-
- int _chain(prog,args) - chain using PATH
- Chains to a new program after finding it in PATH
- Returns: -1=prog not found/error
- -2=not a .EXE or .COM file
- otherwise doesn't return
- Where:
- char *prog=program to chain
- char *args=arguments for prog
-
- char *GetPath(prog,path) - Get the PATH for an executable
- Returns: Pointer to path for the prog
- 0 for program not found
- Where:
- char *prog=program to find
- char *args=buffer to hold path for prog including prog name
-
-
- GETENV.C --
- char *GetEnv(variable, buffer, len)
- Retrieves the contents of an environment variable set with the
- DOS command SET VAR=CONTENTS.
- Returns: Address of buffer
- 0 if variable not found
- Where:
- char *variable=environment variable to retrieve e.g., "PATH"
- char *buffer =holding place for environment variable
- should be at least 128 chars unless you
- know that the variable will be less
- int len =maximum length to copy to buffer including the
- NULL byte '\0' at the end of the string.
-
- e.g., GetEnv("PATH",buffer,80);
- or if(!GetEnv("PATH",buffer,80)) {
- ...
- }
-
- GETTIME.C --
- int GetTime(&hour, &min, &sec) - Get Time Information
- Returns: hundreths of seconds
- Where:
- int hour
- int min
- int sec
-
- int SetTime(hour,min,sec,hundreths) - Set Time Information
- Returns: 0=worked
- -1=error
- Where:
- int hour
- int min
- int sec
- int hundreths
-
- HARDERR.A --
- ERROR codes for hard_err are found in HARDERR.H
- They can be indexed with harderrs[hard_err]
-
- We read about how to do this in the Cware NewLetter and simply translated
- the code into assembler.
-
- void SetHardErr() - Set Up Trap for Device Errors
- No Returns
-
- You can use this by setting hard_err to ERROR and trying to do
- whatever might cause a problem. If a device error occurs, hard_err
- will be set to the number of the error and can be used as an index
- for harderrs[]. This also works well with the INTERRUPT.C functions
- which can be used to save and restore interrupts.
-
- INTEREST.C --
- double interest(p,r,n,y) - Returns Interest Amount for a Loan
-
- This calculates the interest rate for a loan given
- the principal, payment, number of payments per year, and the
- total number of payments for the loan.
- Where:
- double p = principal
- double r = regular payment amount
- int n = number of periods per year
- int y = number of total periods
-
-
- INTERRUPT.C --
- void GetInt(intnum, &segment, &offset)
- Get Current Setting of the an Interrupt
- No Returns
- Where:
- int intnum=interrupt number to retrieve (e.g., 0x24)
- unsigned segment=buffer for the interrupt service routine's
- segment
- unsigned offset =buffer for the interrupt service routine's
- offset past segment
-
- segment:offset is the vector address
-
- void SetInt(intnum, segment, offset)
- Set the Interrupt Service Routine address for and interrupt
- No Returns
- Where:
- int intnum=interrupt number to set (e.g., 0x24)
- unsigned segment=interrupt service routine's segment
- unsigned offset =interrupt service routine's offset past segment
-
- segment:offset is the vector address
-
- SetInt(0x24,_showcs(),myroutine);
- or
- SetInt(0x24,SavedSeg,SavedOffset);
-
- JUL.C --
- long jul(month, day, year) - Returns the number of days since 12/31/39
- Julian dates are in a decent format for comparison.
- Where:
- int month
- int day
- int year
-
- KEYIN.A --
- int KeyIn() - Get a Key from the Keyboard Buffer
- Returns: a character if any available.
- 0 if no key available
-
- This function also adds 128 to function and alt keys
- so that the defines in ALTKEYS.H and FUNKEYS.H can be
- used.
-
- int KeyWait() - See if there is anything in the Keyboard Buffer
- but leave the character in the buffer.
- Returns: a character if any available
- 0 if no key available
-
- int KeyStatus() - See if one of the special keys is pressed.
- Returns: Status where:
- bit:
- 0 - Right Shift Pressed
- 1 - Left Shift Pressed
- 2 - Ctrl/Shift Pressed
- 3 - Alt/Shift Pressed
- 4 - Scroll/Lock State Toggled
- 5 - Numeric Lock State Toggled
- 6 - Caps Lock State Toggled
- 7 - Insert State Active
-
- Defines for the above are in KeyStatus.h
- RIGHT_SHIFT 0x01
- LEFT_SHIFT 0x02
- CTRL_SHIFT 0x04
- ALT_SHIFT 0x08
- SCROLL_LOCK 0x10
- NUM_LOCK 0x20
- CAPS_LOCK 0x40
- INSERT_KEY 0x80
-
- LASTPAY.C --
- double lastpay(r,p,i,n,y)
- Returns: the amount of the Last Payment on a Loan
- Where:
- int r = regular payment amount
- int p = principal of the loan
- int i = annual interest rate
- int n = number of periods per year
- int y = number of total periods
-
- LOCK.C --
- int Lock(offset,length) - Locks parts of files under DOS 3.1
- This can be used by DOS programs that run under network
- environments to lock portions of a file so that multi
- access is not allowed.
- Returns: 0 if worked
- extended error code
- Where:
- long offset=offset in the file to start the lock
- long length=number of bytes in the file to lock
-
- int UnLock(offset,length) - UnLocks parts of files under DOS 3.1
- This should be used to unlock portions of files that were
- locked using Lock(). The UnLock call must look exactly like
- the Lock().
- Returns: 0 if worked
- extended error code
- Where:
- long offset=offset in the file where lock begins
- long length=number of bytes locked
-
- LOGDSK.A --
- int LogDsk(drive) - Set Current Drive Number
- Returns: Number Of disk drives attached
- 0 if invalid drive specified
- Where:
- int drive = 0=A, 1=B, 2=C, ...
-
- When you log a drive it does not actually check to see if
- a diskette is in the drive until you attempt to read or write.
- If you want to check whether or not a diskette is in the
- drive do a dummy open and close and check hard_err.
-
- MEMORY.A --
- long MemSize() - Get Total Memory the System Has Installed
- Returns: Total memory
-
- long MemAvail() - Get Total Available Memory
- Returns: Available Memory
- This memory includes that taken up by your program. In other
- words the total memory is that which you would have if your
- program was not executing.
-
- MINWITH.C --
- double minwith(r,i,n,y) - Minimum Amount you need to Invest to
- Withdraw a Fixed Amound Every Period.
-
- This calculates the initial amount required to be
- able to withdraw a specified amount on a regular basis.
- The calculation requires the amount of the withdrawal,
- nominal interest rate, number of withdrawals per year,
- and the total number of withdrawals (assumes 1 withdrawal
- per period).
-
- Returns: Minimum investment
- Where:
- double r = regular withdrawal
- double i = annual interest rate
- int n = number of withdrawals per year
- int y = number of total withdrawals
-
- MKDIR.A --
- int MkDir(directory) - Create a New Directory
- Returns: 0=made directory successfully
- 3=not a good path in str
- 5=could not make directory
- Where:
- char *directory = directory to create
-
- MODS.A --
- int ChMod(file,attribute) - Change Attributes for a File
- Returns: 0=successful
- 2=file not found
- 3=path not found
- 4=access denied
- Where:
- char *file = file to change
- int attribute = attribute of the file
-
- Attributes are in FILEFIND.H and include the following:
- F_NORMAL 0x00
- F_READ_ONLY 0x01
- F_HIDDEN 0x02
- F_SYSTEM 0x04
- F_LABEL 0x08
- F_DIRECTORY 0x10
- F_ARCHIVE 0x20
- F_ALL 0xFF
-
- e.g., ChMod("MYFILE",F_NORMAL|F_READ_ONLY|F_HIDDEN);
-
- int GetMod(file,&attribute) - Get Attributes for a File
- Returns: 0=successful
- 2=file not found
- 3=path not found
- 4=access denied
- Where:
- char *file = file to change
- int attribute = buffer to store attribute of the file
- Notice that attribute is an integer pointer.
-
- NOMINAL.C --
- double nominal(p,f,n,y) - Nominal Interest Rate for a Loan
-
- This calculates the nominal interest rate for an investment
- given the initial amount, the expected future amount, the
- number of compounding periods per year, and the total number
- of periods the investment will exist.
- Returns: Nominal Interest Rate
- Where:
- double p = principal (initial investment)
- double f = future value of the investment
- int n = number of payments per year
- int y = number of total payments
-
- PAYMENT.C --
- double payment(p,i,n,y) - Payment Amount for a Loan
-
- This calculates the payment required to repay a loan
- given the principal, interest, number of payments per year, and
- the number of total periods (e.g., months) the loan will exist.
- Returns: Payment Amount
- Where:
- double p = principal
- double i = interest payment rate
- int n = number of periods per year
- int y = number of total periods
-
- PRINCIPAL --
- double principal(r,i,n,y) - Principal for a Loan
-
- This calculates the amount that can be borrowed on a loan
- given the payment, interest, number of payments per year, and the
- number of total periods (e.g., months) the loan will exist.
- Returns: Principal of the Loan
- Where:
- double r = regular payment
- double i = interest payment rate
- int n = number of periods per year
- int y = number of total periods
-
- PV.C --
- double pv(f,i,n,y) - Present Value of a Future Sum
-
- This calculates the initial amount needed to reach
- a future value for an investment given the future value,
- annual interest, number of compounding periods per year,
- and the total number of periods the investment will exist.
- Returns: Present Value
- Where:
- double f = future value
- double i = annual interest rate
- int n = number of periods per year
- int y = number of total periods
-
- REBOOT.A --
- void Reboot() - Performs a software reboot of the system.
-
-
- REGDEPOSIT.C --
- double regdeposit(f,i,n,y) - Regular Deposit Needed to Reach a
- Future Sum.
-
- This calculates the deposit amount required to reach
- a desired future value given the future value, nominal interest
- rate, number of deposits per year, and the total number of
- deposits that will be made (assumes 1 deposit per period)
- Returns: Regular Deposit
- Where:
- double f = future value desired
- double i = annual interest rate
- int n = number of deposits per year
- int y = number of total deposits
-
- RESET.A --
- void Reset() - Resets the disk drives and flushes all of the file
- buffers.
-
-
- RMDIR.A --
- int RmDir(directory) - Remove a directory
- Returns: 0=made directory successfully
- 3=not a good path in str
- 5=could not make directory
- Where:
- char *directory = directory to create
-
- ROUND.C --
- double round(v,s) - Rounds to Significant Decimal Figure
- Returns: Rounded Result of V
- Where:
- double v = value to round
- int s = significant places ((-) left of decimal point
- (+) right of the decimal point)
-
- SLEEP.C --
- void sleep(seconds) - Pauses Execution of a Program for (seconds)
- Where:
- int seconds = # of seconds to wait
-
-
- STRINDEX.C --
- char *StrIndex(t,s) - Find a String Token in a given line.
- Returns: 0 = string not found
- Address of the string in the line
- Where:
- char *t = pointer to token to find
- char *s = pointer to string to seach
-
- STRLOWER.C --
- char *StrLower(s) - Convert a String to Lower Case
- Returns: The address of the buffer you passed thru so that
- you can do stuff like printf("%s",StrLower(s));
- Where:
- char *s = pointer to string to convert
-
-
- STRUPPER.O
- char *StrUpper(s) - Convert a String to Upper Case
- Returns: The address of the buffer you passed thru so that
- you can do stuff like printf("%s",StrUpper(s));
- Where:
- char *s = pointer to string to convert
-
- TERM.C --
- double term(p,i,n,y) - Term of a Loan
-
- This calculates the number of periods (e.g., months)
- a loan will exist given the principal, interest,
- number of payments per year, and the payment per period
- for the loan.
- Returns: Term of the Loan
- Where:
- double p = principal of the loan
- double i = annual interest rate
- int n = number of periods per year
- int y = number of total periods
-
- TICKS.A --
- long Ticks() - Get Clock Ticks
- Returns: Current Clock Tick Count. The PC clock ticks about
- 18.21 times per second.
-
- TIMESTAMP.A --
- int GetStamp(file,&dosdate) - Get Modification Time for a File.
- Returns: 0=Worked
- 2/4=File Not Found
- 5=Access Denied
- Where:
- char *file = Pointer to File Name
- long *dosdate = Long Buffer for the Date/Time Info
-
- int SetStamp(file,dosdate) - Set the Modification Time for a File.
- Returns: 0=Worked
- 2/4=File Not Found
- 5=Access Denied
- Where:
- char *file = Pointer to File Name
- long dosdate = Long which contains the Date/Time Info
-
- File time stamps are calculated with the formula:
- time = hour * 2048 + minute * 32 + seconds/2
- date = (year-1980) * 512 + month * 32 + day
- The time will be in the high order 2 bytes and the date in the lower.
-
- The Time Format is:
- F E D C B A 9 8 7 6 5 4 3 2 1 0
- +---------------------------------+
- | HOURS | MINUTES | SECS/2 |
- +---------------------------------+
-
- The Date Format is:
- F E D C B A 9 8 7 6 5 4 3 2 1 0
- +---------------------------------+
- | YEAR-1980 | MONTH | DAY |
- +---------------------------------+
-
-
- VERIFY.A --
- int GetVerify() - Get the Current Setting of the DOS VERIFY Command
- Returns: 0=OFF
- 1=ON
-
- void SetVerify(VerifyVal) - Sets the Verify Flag.
- Where:
- int VerifyFlag = 0=OFF or 1=ON
-
- VERSION.A --
- int DosVer() = Gets Current DOS Version.
- Returns: 0 if DOS version < 2
- otherwise version in high byte and release in low byte.
-
- WITHDRAW.A --
- double withdraw(p,i,n,y) - Amount you can Withdraw for an Investment.
-
- This calculates the amount that can be withdrawn
- from an investment an a regular basis given the initial amount,
- nominal interest rate, number of withdrawals per year, and
- the total number of withdrawals (assumes 1 withdrawal per period)
- Returns: Amount you can Withdraw
- Where:
- double p = present value
- double i = annual interest rate
- int n = number of withdrawals per year
- int y = number of total withdrawals
-
- ------------------------------------------------------------------------
- Sample Programs:
- CAT.C - Similar to Unix cat command.
-
- CHMOD.C - Set attributes for DOS files. This one is similar to the
- Unix function of the same name. Wild Cards are supported.
-
- CP.C - Similar to Unix cp command.
-
- DATETIME.C - Displays the current date and time.
-
- MV.C - Similar to Unix mv command.
-
- POP.C - Restore the directory path saved with the PUSH.EXE command.
-
- PUSH.C - Save the current directory path and move to another. Enter
- the command: PUSH newdirectory <CR> to move to the new
- directory and save the old one. The path is saved in file
- \PUSH.@@@
-
- REB.C - Reboot the Computer/REBOOT.EXE
-
- SPACE.C - Displays the current memory and disk sizes.
-
- STUFF.C - Get equipment status.
-
- TOUCH.C - Set time attributes for a file to the current clock setting.
-
- Other Stuff:
- CURSOR.EXE - Sets the DOS Cursor.
-
- PRT.EXE - Formatted printing routine.
-
-
-